﻿namespace AnyOffice.Components
{
    using log4net;
    using System;
    using System.Collections;
    using System.Reflection;

    public class ModulePage : BasePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        private void HavePermission()
        {
            Hashtable sysFunction = ApplicationCache.SysFunction;
            UserCache cache = new UserCache();
            string str = "," + cache.FuncIdStr + ",";
            string str2 = base.Server.MapPath(".").ToLower();
            if (str2.IndexOf("general") >= 0) str2 = str2.Substring(str2.IndexOf("general") + 7);
            if (str2.StartsWith(@"\")) str2 = str2.Substring(1);
            string key = str2.Replace(@"\", "/");
            if (sysFunction.ContainsKey(key))
            {
                int num = Convert.ToInt32(sysFunction[key]);
                if (str.IndexOf("," + num.ToString() + ",") < 0)
                {
                    base.Response.Write(base.ShowMessage("您不具备该模块的权限"));
                    base.Response.End();
                }
            }
            else
            {
                IDictionaryEnumerator enumerator = sysFunction.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (str.IndexOf("," + enumerator.Value + ",") >= 0 && enumerator.Key.ToString().StartsWith(key)) return;
                }
                base.Response.Write(base.ShowMessage("您不具备该模块的权限"));
                base.Response.End();
            }
        }

        protected override void OnInit(EventArgs O)
        {
            base.OnInit(O);
           

                
             if (!this.DesignMode)
 	        {
                try
                {

                    this.HavePermission();

                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled) { log.Error("", exception); }
                }
            }
              
 	       

           
        }
    }
}

